<!doctype html>
<html lang="zh-CN">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
	<meta http-equiv="X-UA-Compatible" content="ie=edge">
	<title>ajax</title>
	
	<script src="ajax.js"></script>
	<script src="cookie.js"></script>
</head>
<body>

<form id="form_login"  method="get" enctype="application/x-www-form-urlencoded">
	
	<input type="text" id="user_name" name="user_name" value="" placeholder="请输入姓名">
	
	<input type="password" id="pwd" name="pwd" value="" placeholder="请输入密码">
	
	<button type="button" onclick="login()">登录</button>

</form>

<br>

<button onclick="myGetCookie()">获取cookie</button>
<button onclick="mySetCookie()">设置cookie</button>

</body>
<script>

    /**
     * 登录
     */
    function login() {

        alert("要登录了哦");

        let data = {}; //要提交的数据
        data.name = document.getElementById("user_name").value;
        data.pwd = document.getElementById("pwd").value;

        //Todo:url通常写在公共配置文件中
        ajax.post("http://lession.fhh.ronmei.net/0102/server.php", data, function(res)  {
            alert("已登录了");
            console.log(res);
            return false;
        });
   

        //阻止表单提交
        // return false;
    }

    function myGetCookie() {
        let cookies = getCookie();
        console.log(cookies);

    }

    function mySetCookie() {
        setCookie("name", "fhh", 10);
    }

</script>
</html>